VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Hashtable"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'Hashtable class v1.00
'Made 28/08/06 by Me!

Private Type hashentry
    key As String
    data As Variant
End Type

Dim Hashtable() As hashentry
Dim hashsize As Long

Private Sub Class_Initialize()
ReDim Hashtable(0)
hashsize = 0
End Sub

Private Sub Class_Terminate()
Erase Hashtable
End Sub

Private Function hashfunc(x As String) As Long
cnt = 13

For y = 1 To Len(x)
cnt = cnt + Asc(Mid(x, y, 1)) * (17 ^ (y + 2)) + 23
cnt = cnt - (Int(cnt / hashsize) * hashsize)
Next y

cnt = cnt - (Int(cnt / hashsize) * hashsize) 'Final modulous

hashfunc = cnt
End Function

Public Sub Enterdata(key As String, data As Variant)
Dim hkey As Long
Dim oneloop As Boolean
hkey = hashfunc(key)
Do Until Hashtable(hkey).key = key Or Hashtable(hkey).key = ""
hkey = hkey + 1
If hkey > hashsize Then
    If oneloop Then Exit Sub
    hkey = 0
    oneloop = True
End If
Loop
Hashtable(hkey).key = key
Hashtable(hkey).data = data
End Sub

Public Function Getdata(key As String)
Dim hkey As Long
Dim oneloop As Boolean

hkey = hashfunc(key)

Do Until Hashtable(hkey).key = key Or Hashtable(hkey).key = ""
hkey = hkey + 1
If hkey > hashsize Then
    If oneloop Then Exit Function
    hkey = 0
    oneloop = True
End If
Loop
If Hashtable(hkey).key = "" Then Exit Function 'It doesn't exist
Getdata = Hashtable(hkey).data
End Function

Public Function Keyexist(key As String) As Boolean
hkey = hashfunc(key)
Do Until Hashtable(hkey).key = key
hkey = hkey + 1
Loop
End Function

Public Sub resize(nval As Long)
ReDim Hashtable(nval + 1)
hashsize = nval
End Sub

Public Function getrec(num As Long)
getrec = Hashtable(num).data
End Function

Public Function getkey(num As Long)
getkey = Hashtable(num).key
End Function

Public Sub clear()
ReDim hashfunc(hashsize + 1)
End Sub

Public Function size() As Long
size = hashsize
End Function
